package com.itcast.demo.validate.controller;

import com.itcast.demo.validate.pojo.UserGroup;
import com.itcast.demo.validate.pojo.UserGroupSequence;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/validate")
@Validated
public class ValidateController3 {

    // 顺序校验分组  注意：createUser方法会首先验证username字段（Group1），然后验证password字段（Group2）

    @PostMapping("/create1")
    public ResponseEntity<String> createUser(@RequestBody @Validated(UserGroupSequence.GroupA.class) UserGroupSequence user) {
        // 创建用户逻辑
        return ResponseEntity.ok("用户创建成功");
    }

    @PostMapping("/update2")
    public ResponseEntity<String> updateUser(@RequestBody @Validated(UserGroupSequence.GroupB.class) UserGroupSequence user) {
        // 更新用户逻辑
        return ResponseEntity.ok("用户更新成功");
    }

}


